package com.travelsky.airchina.boarding.dao.impl.hibernate;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.travelsky.airchina.boarding.dao.CategoryAttributeCandidateValueDAO;
import com.travelsky.airchina.boarding.domain.CategoryAttributeCandidateValue;


@Repository("categoryAttributeCandidateValueDAO")
public class CategoryAttributeCandidateValueDAOImpl extends GenericDAOHibernate<CategoryAttributeCandidateValue, Long,CategoryAttributeCandidateValueDAO> implements CategoryAttributeCandidateValueDAO {
	@Autowired
	public CategoryAttributeCandidateValueDAOImpl(SessionFactory sessionFactory){
		this.setSessionFactory(sessionFactory);
	}
	public void deleteCategoryAttributeCandidateValueByCategoryAttributeId(Long id) {
		String hql = "delete from CategoryAttributeCandidateValue where categoryAttribute.id = ? ";
		this.getHibernateTemplate().bulkUpdate(hql, id);
	}

	@SuppressWarnings("unchecked")
	public List<CategoryAttributeCandidateValue> findCategoryAttributeCandidateValueByCategoryAttributeId(
			List<Long> attributeIdList) {
		String hql = " select c_ from CategoryAttributeCandidateValue c_ where c_.categoryAttribute.id in ( :attributeIdList ) and c_.status = :status ";
		Query query = this.getSession().createQuery(hql);
		query.setParameterList("attributeIdList", attributeIdList,Hibernate.LONG);
		query.setParameter("status", "1",Hibernate.STRING);
		return query.list();
	}
	@SuppressWarnings("unchecked")
	public List<Object[]> findCandidateIdAndValue(List<Long> candidateIds) {
		String hql = " select candidate_value_.id,candidate_value_.value from CategoryAttributeCandidateValue candidate_value_ where candidate_value_.id in (:candidateIds)";
		Query query = this.getSession().createQuery(hql);
		query.setParameterList("candidateIds", candidateIds,Hibernate.LONG);
		return query.list();
	}


}
